/**************** STUDY 3 ****************/

* Authoritarian Reforms and External Legitimacy, by Calvert W. Jones

* Using Stata/MP 17. Please call up Study3_Data from the appropriate directory.


* Use appropriate directory
import delimited "...\Study3_Data", varnames(1) case(preserve)


* Prepare attributes for conjoint analysis 

encode pconservative, gen(attribute_pconservative)
encode pwealth, gen(attribute_pwealth)
encode poil, gen(attribute_poil)
encode pgovtype, gen(attribute_pgovtype)
encode ptourism, gen(attribute_ptourism)
encode pally, gen(attribute_pally)
encode pcritics, gen(attribute_pcritics)
encode preform, gen(attribute_preform)
encode pexperts, gen(attribute_pexperts)
encode pnationality, gen(attribute_pnationality)
encode presponse, gen(attribute_presponse)

gen panyReform=.
replace panyReform=0 if preform=="control"
replace panyReform=1 if preform=="anticorruption" | preform=="climate change" | preform=="horizontal" | preform=="liberal" | preform=="poverty" | preform=="proamerican" | preform=="science" | preform=="vertical"


* Generate/label DVs

label define favorableLabels 1 "Very unfavorable" 2 "Unfavorable" 3 "Somewhat unfavorable" 4 "Neutral" 5 "Somewhat favorable" 6 "Favorable" 7 "Very favorable"
label values fav favorableLabels
label values trade favorableLabels
label values cut favorableLabels
label values boycott favorableLabels
label values visit favorableLabels


label var fav "Favorability"
label var trade "Trade"
label var cut "Cutting off relations"
label var boycott "Boycott"


/* Stata's default baselines are alphabetical as follows

attribute_pconservative 
1 somewhat liberal 2 very conservative
baseline 1

attribute_pwealth
1 not very 2 very
baseline 1

attribute_poil
1 natural resources 2 oil and other fossil fuels
baseline 1

attribute_pgovtype
1 a military dictatorship 2 a monarchy, ruled by a king and royal family 3 autocratic, led by a single political party
baseline 1

attribute_ptourism
1 modern airport, good hotels and restaurants, and a striking natural landscape 2 small airport, some inexpensive hotels, and beautiful landscapes
baseline 2

attribute_pally
1 a US ally, with a strong trade relationship 2 not an ally of the United States, with a weak trade relationship
baseline 2

attribute_pcritics
1 not a democracy 2 not a democracy, lacks a free press, and denies civil liberties to many citizens
baseline 1

attribute_preform
1 anticorruption 2 climate change 3 control 4 horizontal 5 liberal 6 poverty 7 proamerican 8 science 9 vertical
baseline 3

attribute_pexperts
1 experts 2 the ruler
baseline 2

attribute_pnationality
1 American 2 Chinese 3 international 4 local
baseline 4

attribute_presponse
1 positive/neutral response 2 skeptical response
baseline 1
*/

/* Re-order attribute levels for some attributes so that they appear in a more natural order within figures */ 


* Development - make "low" the baseline
gen attribute_ptourismR=.
replace attribute_ptourismR=1 if attribute_ptourism==2	  
replace attribute_ptourismR=2 if attribute_ptourism==1
* To check: browse ptourism attribute_ptourism attribute_ptourismR
* Now, 1=low and 2=high

* Geopolitical value (ally) - make "not a US ally" the baseline  
gen attribute_pallyR=.
replace attribute_pallyR=1 if attribute_pally==2	  
replace attribute_pallyR=2 if attribute_pally==1
* To check: browse pally attribute_pally attribute_pallyR
* Now, 1=not a US ally (low geopolitical value) and 2=US ally (high geopolitical value)


* Reform - Make "no reform" the baseline of 1, and also change the order to match Study 1's previous studies as closely as possible (though reforms here are different, see manuscript)

gen attribute_preformR=.
replace attribute_preformR=1 if attribute_preform==3 // Control/no reform is baseline=1 (was 3)
replace attribute_preformR=2 if attribute_preform==5 // Liberal (womens rights, was 5) 
replace attribute_preformR=3 if attribute_preform==4 // Horizontal (was 4)
replace attribute_preformR=4 if attribute_preform==9 // Vertical (was 9)
replace attribute_preformR=5 if attribute_preform==2 // Climate change (was 2)
replace attribute_preformR=6 if attribute_preform==8 // Science (was 8)
replace attribute_preformR=7 if attribute_preform==6 // Poverty (was 6)
replace attribute_preformR=8 if attribute_preform==1 // Anticorruption (was 1)
replace attribute_preformR=9 if attribute_preform==7 // Proamerican (was 7)
* To check: browse preform attribute_preform attribute_preformR
* So now 1=no reform, 2=liberal, 3=horizontal, 4=vertical, 5=climate change, 6=science, 7=poverty; 8=anti-corruption, 9=proamerican


* Technocratic/experts - make "the ruler" (non-technocratic, or no experts involved) the baseline
gen attribute_pexpertsR=.
replace attribute_pexpertsR=1 if attribute_pexperts==2
replace attribute_pexpertsR=2 if attribute_pexperts==1
* To check: browse pexperts attribute_pexperts attribute_pexpertsR
* Now, 1=no experts involved ("the ruler") and 2=experts involved


/* Label attributes, including reordered ones */

label var attribute_pconservative "Culture"
label define attribute_pconservative_values 1 "Somewhat liberal" 2 "Very conservative"
label values attribute_pconservative attribute_pconservative_values 

label var attribute_pwealth "Wealth" 
label define attribute_pwealth_values 1 "Low" 2 "High"
label values attribute_pwealth attribute_pwealth_values 

label var attribute_pgovtype "Type of government"
label define attribute_pgovtype_values 1 "Military dictatorship" 2 "Authoritarian monarchy" 3 "Single party dominant"
label values attribute_pgovtype attribute_pgovtype_values 

* Note this is a variable with reordered attribute levels (R at the end for "reordered")
label var attribute_ptourismR "Economic development"
label define attribute_ptourismR_values 1 "Low" 2 "High"
label values attribute_ptourismR attribute_ptourismR_values 

* Likewise, this is avariable with reordered attribute levels (R at the end for "reordered")
label var attribute_pallyR "Geopolitical value"
label define attribute_pallyR_values 1 "Not a US ally" 2 "US ally"
label values attribute_pallyR attribute_pallyR_values 

label var attribute_pcritics "Depth of autocracy"
label define attribute_pcritics_values 1 "Autocracy" 2 "Repressive autocracy" 
label values attribute_pcritics attribute_pcritics_values 


label var attribute_preformR "Reform type"
label define attribute_preformR_values 1 "No reform" 2 "Liberal/Diagonal accountability" 3 "Horizontal accountability" 4 "Vertical accountability" 5 "Environment/climate change" 6 "Science and technology" 7 "Global poverty" 8 "Anticorruption" 9 "Pro-American"
label values attribute_preformR attribute_preformR_values 

* Last attribute with reordered levels (R at the end for "reordered")
label var attribute_pexpertsR "Technocratic"
label define attribute_pexpertsR_values 1 "No experts" 2 "Experts involved" 
label values attribute_pexpertsR  attribute_pexpertsR_values 

label var attribute_pnationality "Expert nationality"
label define attribute_pnationality_values 1 "American" 2 "Chinese" 3 "International" 4 "Local"
label values attribute_pnationality attribute_pnationality_values 


label var attribute_presponse "Observers' response"
label define attribute_presponse_values 1 "Neutral" 2 "Skeptical"
label values attribute_presponse attribute_presponse_values 

label var panyReform "Reform"
label define panyReform_values 0 "No reform" 1 "Reform"
label values panyReform panyReform_values



/* Analysis */
/* Note: To align with the PAP, the two exploratory reforms (labeled as exploratory in the PAP) are excluded from this analysis, though results for them are reported in the appendix; see appendix. 
*/

** Favorability

* Using panyReform vs. control (no reform)
regress fav i.panyReform i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics if attribute_preformR!=8 & attribute_preformR!=9, cluster(ResponseId)
estimates store fav_any_NoExp

* Using all individual reforms vs. control (no reform)
regress fav i.attribute_preformR i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics if attribute_preformR!=8 & attribute_preformR!=9, cluster(ResponseId)
estimates store fav_results_NoExp

** Trade with country

* Using panyReform vs. control (no reform)
regress trade i.panyReform i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics if attribute_preformR!=8 & attribute_preformR!=9, cluster(ResponseId)
estimates store trade_any_NoExp

* Using all individual reforms vs. control (no reform)
regress trade i.attribute_preformR i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics if attribute_preformR!=8 & attribute_preformR!=9, cluster(ResponseId)
estimates store trade_results_NoExp

** Cut off relations

* Using panyReform vs. control (no reform)
regress cut i.panyReform i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics if attribute_preformR!=8 & attribute_preformR!=9 , cluster(ResponseId)
estimates store cut_any_NoExp

* Using all individual reforms vs. control (no reform)
regress cut i.attribute_preformR i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics if attribute_preformR!=8 & attribute_preformR!=9, cluster(ResponseId)
estimates store cut_results_NoExp


** Boycott

* Using panyReform vs. control (no reform)
regress boycott i.panyReform i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics if attribute_preformR!=8 & attribute_preformR!=9, cluster(ResponseId)
estimates store boycott_any_NoExp

* Using all individual reforms vs. control (no reform)
regress boycott i.attribute_preformR i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics if attribute_preformR!=8 & attribute_preformR!=9, cluster(ResponseId)
estimates store boycott_results_NoExp


* Create Figure 9 in manuscript

**# Bookmark #1
coefplot (fav_any_NoExp, msymbol(O) mcolor(black) label("Favorability") offset(.3)) (trade_any_NoExp, msymbol(S) mcolor(black) label("Trade with country") offset(.1)) (cut_any_NoExp, msymbol(T) mcolor(black) label("Cut off relations") offset(-.1)) (boycott_any_NoExp, msymbol(D) mcolor(black) label("Boycott") offset(-.3)) (fav_results_NoExp, msymbol(O) mcolor(black) label("Favorability") offset(.3)) (trade_results_NoExp, msymbol(S) mcolor(black) label("Trade with country") offset(.1)) (cut_results_NoExp, msymbol(T) mcolor(black) label("Cut off relations") offset(-.1)) (boycott_results_NoExp, msymbol(D) mcolor(black) label("Boycott") offset(-.3)), keep(*.panyReform *.attribute_preformR) headings(0.panyReform="{bf:Any Reform vs. Control}" 1.attribute_preformR="{bf:Inward-Facing Reforms vs. Control}" 5.attribute_preformR="{bf:Outward-Facing Reforms vs. Control}" 8.attribute_preformR="{bf:Exploratory Reforms vs. Control}") xline(0, lcolor(black))  baselevels drop(_cons) levels(95 90) graphregion(color(white)) bgcolor(white) lcolor(black) ciopts(color(black black)) xscale(range(-.6 .6)) scale(.7) aspect(2) legend(order(3 6 9 12) col(1) position(3))

* Generate table
esttab fav_any_NoExp trade_any_NoExp cut_any_NoExp boycott_any_NoExp, label se keep(*.panyReform)
esttab fav_results_NoExp trade_results_NoExp cut_results_NoExp boycott_results_NoExp, label se keep(*.attribute_preformR)


** Testing H7 in manuscript (supported) - "Reforms focused on gender equality will be most powerful, particularly in terms of positive benefits."

* Create variable with values for control, liberal (included women's rights), and all other reforms

gen womenandrests3 = .
replace womenandrests3 = 1 if preform=="control"
replace womenandrests3 = 2 if preform=="liberal"
replace womenandrests3 = 3 if preform!="liberal" & preform!="control"

label var womenandrests3 "Reform"
label define womenandrests3_values 1 "No Reform" 2 "Liberal" 3 "All other reforms"
label values womenandrests3 womenandrests3_values


* Favorability (excluding 2 exploratory reforms)
regress fav i.womenandrests3 i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics if attribute_preformR!=8 & attribute_preformR!=9, cluster(ResponseId)
estimates store fav_womenvall

lincom 2.womenandrests3 - 3.womenandrests3

* Trade (excluding 2 exploratory reforms)

regress trade i.womenandrests3 i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics if attribute_preformR!=8 & attribute_preformR!=9, cluster(ResponseId)
estimates store trade_womenvall

lincom 2.womenandrests3 - 3.womenandrests3

* Cut (excluding 2 exploratory reforms)

regress cut i.womenandrests3 i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics if attribute_preformR!=8 & attribute_preformR!=9, cluster(ResponseId)
estimates store cut_womenvall

lincom 2.womenandrests3 - 3.womenandrests3

* Boycott (excluding 2 exploratory reforms)
regress boycott i.womenandrests3 i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics if attribute_preformR!=8 & attribute_preformR!=9, cluster(ResponseId)
estimates store boycott_womenvall

lincom 2.womenandrests3 - 3.womenandrests3



** Testing H8 (supported) and H9 (not supported) in manuscript

/* H8 "Inward-facing reforms will be associated with greater legitimacy gains, compared to outward-facing reforms, in terms of positive benefits." */

/* H9 - "Outward-facing reforms will be associated with greater legitimay gains, compared to inward-facing reforms, in terms of shielding benefits." */

* Create index for positive/participatory benefits

egen fav_trade_index = rowmean(fav trade)

* Create index for shielding benefits (use absolute values)

egen cut_boycott_index = rowmean(cut boycott)

* Convert shielding benefits index to an index using absolute values; we need to compare the absolute value/size of coefficients so that higher scores indicate greater benefits. 

gen cut_rec = cut 
recode cut_rec (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1)
gen boycott_rec = boycott 
recode boycott_rec (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1)

egen cb_index_rec = rowmean(cut_rec boycott_rec)


* Create a variable for all inward-facing reforms (liberal, horizontal, vertical)
gen in_lhv=.
replace in_lhv=1 if preform=="liberal" | preform=="horizontal" | preform=="vertical"

* Create a variable for all outward-facing reforms (climate change, science, poverty)
gen out_csp=.
replace out_csp=1 if preform=="climate change" | preform=="science" | preform=="poverty"

*  Create a categorical/factor variable so that 1=no reform/control; 2=inward-facing reforms; 3=outward-facing reforms
gen in_lhv_out_csp_control = .
replace in_lhv_out_csp_control = 1 if preform=="control" // baseline
replace in_lhv_out_csp_control = 2 if in_lhv==1
replace in_lhv_out_csp_control = 3 if out_csp==1

* Label the new variables
label var in_lhv "Inward-Facing Reforms"
label var out_csp "Inward-Facing Reforms"

label var in_lhv_out_csp_control "Reform Type"
label define in_lhv_out_csp_control_values 1 "No reform" 2 "Inward-Facing Reforms" 3 "Outward-Facing Reforms"
label values in_lhv_out_csp_control in_lhv_out_csp_control_values

* Test for the equality of coefficients in one regression - H8 is supported
/* Note: The 2 exploratory reforms are automatically excluded since they are not part of the indices.*/

regress fav_trade_index i.in_lhv_out_csp_control i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics , cluster(ResponseId)

test 2.in_lhv_out_csp_control=3.in_lhv_out_csp_control
lincom 2.in_lhv_out_csp_control - 3.in_lhv_out_csp_control

* Test for the equality of coefficients in one regression - H9 is not supported
/* Note: The 2 exploratory reforms are automatically excluded since they are not part of the indices.*/

regress cb_index_rec i.in_lhv_out_csp_control i.attribute_pgovtype i.attribute_pallyR i.attribute_pconservative i.attribute_pwealth i.attribute_ptourismR  i.attribute_pcritics, cluster(ResponseId)

test 2.in_lhv_out_csp_control=3.in_lhv_out_csp_control
lincom 2.in_lhv_out_csp_control - 3.in_lhv_out_csp_control


